﻿package plugin.shouchong
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.external.*;
    import flash.geom.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import uiresource.*;
    import view.mornExtends.*;
    import view.uilt.*;

    public class NewShouChongCtrl extends ShouChongUI
    {
        private var _close:Function;
        private var _loading:Boolean = false;
        private var wuqiMc:XMLMovieClip;
        private var buttonMc:XMLMovieClip;

        public function NewShouChongCtrl(param1:Function)
        {
            this._close = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            var _loc_1:* = Control.create(ShouchongControl, this);
            ModelProxy.addObserver("shouchong", _loc_1);
            this.showItem();
            lingquBtn.visible = false;
            lingquBtn.addEventListener(MouseEvent.CLICK, this.onLingQu);
            lingquBtn.disabled = true;
            chongqianBtn.addEventListener(MouseEvent.CLICK, this.onChongQian);
            closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            XMLMcManager.instance.complatefuncs["shouchong"] = this.mcCompletefunc;
            if (int(UserData.getOnlineData("shouchong")) == 1)
            {
                this.reshow();
            }
            return;
        }// end function

        private function mcCompletefunc() : void
        {
            var _loc_1:* = UserData.getUserData("career");
            if (_loc_1 == 1)
            {
                this.wuqiMc = XMLMcManager.instance.getPluginMc("shouchong", "tulong");
            }
            else if (_loc_1 == 2)
            {
                this.wuqiMc = XMLMcManager.instance.getPluginMc("shouchong", "fazhang");
            }
            else
            {
                this.wuqiMc = XMLMcManager.instance.getPluginMc("shouchong", "yitian");
            }
            if (this.wuqiMc)
            {
                if (_loc_1 == 1)
                {
                    this.wuqiMc.x = -377 + 259;
                    this.wuqiMc.y = -73 + 27;
                    this.wuqiMc.interval = 1000 / 8;
                }
                else if (_loc_1 == 2)
                {
                    this.wuqiMc.x = -312 + 259;
                    this.wuqiMc.y = -49 + 27;
                }
                else
                {
                    this.wuqiMc.x = -317 + 259;
                    this.wuqiMc.y = -33 + 27;
                }
                this.wuqiMc.play();
                this.wuqiMc.mouseChildren = false;
                this.wuqiMc.mouseEnabled = false;
                this.addChild(this.wuqiMc);
            }
            if (int(UserData.getOnlineData("shouchong")) != 1)
            {
                this.buttonMc = XMLMcManager.instance.getPluginMc("shouchong", "shouchong_cq");
                if (this.buttonMc)
                {
                    this.buttonMc.x = 500 - 194;
                    this.buttonMc.y = 370 + 41;
                    this.buttonMc.mouseChildren = false;
                    this.buttonMc.mouseEnabled = false;
                    this.buttonMc.blendMode = BlendMode.ADD;
                    this.buttonMc.interval = 1000 / 8;
                    this.buttonMc.visible = true;
                    this.addChild(this.buttonMc);
                }
            }
            else if (this.buttonMc)
            {
                this.buttonMc.visible = false;
            }
            return;
        }// end function

        public function openRefresh() : void
        {
            this.mcCompletefunc();
            return;
        }// end function

        private function showItem() : void
        {
            var _loc_1:int = 241102033;
            var _loc_2:* = new Array();
            _loc_2 = ItemUilt.getBoxArr(_loc_1);
            var _loc_3:Array = [];
            var _loc_4:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2.length)
            {
                
                _loc_3.push(_loc_2[_loc_5]);
                _loc_5++;
            }
            list1.array = _loc_3;
            list1.renderHandler = new Handler(this.itemRender1);
            return;
        }// end function

        private function itemRender1(param1:Component, param2:int) : void
        {
            if (param2 < list1.length)
            {
                (param1 as FlashItem).flagshow = true;
                (param1 as FlashItem).effshow = true;
                (param1 as FlashItem).data = list1.array[param2];
                (param1 as FlashItem).changeSuperLvXY(25, 3);
            }
            return;
        }// end function

        private function onChongQian(event:MouseEvent) : void
        {
            if (Config.gameParams.oper == "qq")
            {
                ModelProxy.change("plugin", "open", {target:"qqchongzhi"});
            }
            else
            {
                if (!ItemUilt.canpay)
                {
                    ModelProxy.change("movetips", "error", "功能尚未开放，敬请期待");
                    return;
                }
                ExternalInterface.call("topay");
            }
            return;
        }// end function

        private function onLingQu(event:MouseEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Point = null;
            if (_loc_2)
            {
                while (_loc_2.length > 0)
                {
                    
                    _loc_2.pop();
                }
                _loc_2 = null;
            }
            _loc_2 = [];
            var _loc_3:* = list1.array;
            var _loc_4:Array = [[259, 353], [331, 353], [403, 353], [475, 353], [547, 353], [619, 353]];
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3.length)
            {
                
                _loc_6 = _loc_4[_loc_5][0];
                _loc_7 = _loc_4[_loc_5][1];
                _loc_8 = localToGlobal(new Point(_loc_6, _loc_7));
                _loc_2[_loc_5] = {x:_loc_8.x, y:_loc_8.y};
                _loc_5++;
            }
            ModelProxy.change("data", "scItemPoint", _loc_2);
            PluginManager.instance.sendToServer("xunbao", CMDXunBao.getShoucong, null);
            this.close();
            return;
        }// end function

        public function reshow() : void
        {
            if (chongqianBtn.visible == true)
            {
                chongqianBtn.visible = false;
                chongqianBtn.mouseEnabled = false;
                if (this.buttonMc)
                {
                    this.buttonMc.visible = false;
                }
                lingquBtn.disabled = false;
                lingquBtn.visible = true;
            }
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        private function clearMc() : void
        {
            if (this.wuqiMc && this.wuqiMc.parent)
            {
                this.wuqiMc.parent.removeChild(this.wuqiMc);
            }
            if (this.buttonMc && this.buttonMc.parent)
            {
                this.buttonMc.parent.removeChild(this.buttonMc);
            }
            return;
        }// end function

        private function close() : void
        {
            if (this._close != null)
            {
                this._close();
            }
            this.clearMc();
            return;
        }// end function

    }
}
